package jdbc;

import com.alibaba.druid.pool.DruidDataSource;
import org.junit.Test;

import javax.sql.DataSource;
import java.sql.Connection;
import java.sql.SQLException;

/**
 * Date:2022/2/28
 * Author:ybc
 * Description:
 */
public class DruidTest {

    @Test
    public void testDruid() throws SQLException {
        DruidDataSource dataSource = new DruidDataSource();
        dataSource.setDriverClassName("com.mysql.jdbc.Driver");
        dataSource.setUrl("jdbc:mysql://localhost:3306/wh0106?characterEncoding=utf8");
        dataSource.setUsername("root");
        dataSource.setPassword("123456");
        //最大连接池数量
        //dataSource.setMaxActive(8);
        //初始化时建立物理连接的个数
        dataSource.setInitialSize(8);
        dataSource.setMaxWait(60000);

        Connection connection1 = dataSource.getConnection();
        Connection connection2 = dataSource.getConnection();
        Connection connection3 = dataSource.getConnection();
        Connection connection4 = dataSource.getConnection();
        Connection connection5 = dataSource.getConnection();
        Connection connection6 = dataSource.getConnection();
        Connection connection7 = dataSource.getConnection();
        Connection connection8 = dataSource.getConnection();
        System.out.println(connection8);
        connection8.close();
        Connection connection9 = dataSource.getConnection();
        System.out.println(connection9);
    }

}
